package com.ymtms.customerservice.dao;

import com.ymtms.customerservice.pojo.ComplaintInformation;
import com.ymtms.customerservice.util.TimeRangeUtil;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ComplaintInformationMapper {
    int deleteByPrimaryKey(Integer ciid);

    int insert(ComplaintInformation record);

    int insertSelective(ComplaintInformation record);

    ComplaintInformation selectByPrimaryKey(Integer ciid);

    int updateByPrimaryKeySelective(ComplaintInformation record);

    int updateByPrimaryKey(ComplaintInformation record);

//    @Select("<script> SELECT * FROM complaint_information WHERE flag=0\n" +
//            "    <if test=\"customer !=null and customer !=''\">\n" +
//            "      and customer LIKE '%' #{customer} '%'\n" +
//            "    </if>\n" +
//            "    <if test=\"goodsBillCode !=null and goodsBillCode !=''\">\n" +
//            "      and goods_bill_code = #{goodsBillCode}\n" +
//            "    </if>\n" +
//            "    <if test=\"appealDate !=null and appealDate !=''\">\n" +
//            "      and appeal_date LIKE '%' #{appealDate} '%'\n" +
//            "    </if>\n" +
//            "    <if test=\"ifHandle !=null and ifHandle !=''\">\n" +
//            "      and if_handle = #{ifHandle}\n" +
//            "    </if> </script>")
    public List<ComplaintInformation> selectAll(@Param("customer") String customer, @Param("goodsBillCode")String goodsBillCode,
                                         @Param("appealDate")String appealDate,@Param("ifHandle") String ifHandle);

//    (customer,goods_bill_code,appeal_content,appeal_date,if_handle,deal_date,deal_result,if_callback,call_back_date,deal_person)
    @Insert("INSERT INTO complaint_information(customer,goods_bill_code,appeal_content,appeal_date) values(#{customer},#{goodsBillCode},#{appealContent},#{appealDate})")
    void insertComplaint(String customer, String goodsBillCode, String appealContent, String appealDate);

    @Select("SELECT goods_bill_code FROM goodsbill_master where flag=0 AND send_goods_customer_no=#{customerNO}")
    List<String> selectGoodsBillCodeByCustomerNO(String customerNO);

    /**
     * 处理方式1:退款
     * @param ciid
     * @param dealPerson
     * @param dealDate
     */
    @Update("UPDATE complaint_information SET if_handle='已处理',deal_person=#{dealPerson}," +
                "deal_date=#{dealDate},deal_result='已受理并退款',if_callback='已回告',call_back_date=#{dealDate} WHERE ciid=#{ciid}")
    void refund(Integer ciid,String dealPerson,String dealDate);

    /**
     * 处理方式2，；垃圾信息无视掉
     * @param ciid
     * @param dealPerson
     * @param dealDate
     */
    @Update("UPDATE complaint_information SET if_handle='已处理',flag=1,deal_person=#{dealPerson}," +
                "deal_date=#{dealDate},deal_result='垃圾信息，已忽视',if_callback='已回告',call_back_date=#{dealDate} WHERE ciid=#{ciid}")
    void ignore(Integer ciid, String dealPerson, String dealDate);

    /**
     * 投诉处理3：删除
     * @param ciid
     * @param dealPerson
     * @param dealDate
     */

    @Update("UPDATE complaint_information SET if_handle='已处理',deal_person=#{dealPerson}," +
                "deal_date=#{dealDate},deal_result='已删除',flag=1 WHERE ciid=#{ciid}")
    void delete(Integer ciid, String dealPerson, String dealDate);

    /**
     * 查看所有投诉信息
     * @param complaintInformation
     * @param balanceDateRange
     * @return
     */

    List<ComplaintInformation> queryByPage(@Param("complaintInformation") ComplaintInformation complaintInformation,
                                                @Param("sappealDate") String sappealDate,
                                                @Param("balanceDateRange") TimeRangeUtil balanceDateRange);


}